<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <el-form :inline="true" :model="queryForm">
        <el-form-item label="委托单编号">
          <el-input
            v-model="queryForm.EntrustOrderNum"
            placeholder="委托单编号"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onQuery">查询</el-button>
          <el-button type="primary" @click="entrustTaskDistributionFun"
            >任务接收</el-button
          >
          <el-button type="primary" @click="entrustTaskDistributionFun"
            >转单</el-button
          >
          <el-button type="primary" @click="entrustTaskDistributionFun"
            >导出</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        :data="list"
        element-loading-text="Loading"
        fit
        highlight-current-row
      >
        <el-table-column align="center" label="序号" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column label="委托单号">
          <template slot-scope="scope">
            {{ scope.row.sampleNum }}
          </template>
        </el-table-column>
        <el-table-column label="检测项目">
          <template slot-scope="scope">
            {{ scope.row.detectionItemName }}
          </template>
        </el-table-column>
        <el-table-column label="样品名称">
          <template slot-scope="scope">
            {{ scope.row.sampleName }}
          </template>
        </el-table-column>
        <el-table-column label="样品编号">
          <template slot-scope="scope">
            {{ scope.row.sampleNum }}
          </template>
        </el-table-column>
        <el-table-column label="检测人">
          <template slot-scope="scope">
            {{ scope.row.detectionPersonName }}
          </template>
        </el-table-column>
        <el-table-column label="计划检测时间">
          <template slot-scope="scope">
            {{ scope.row.planDetectionDate }}
          </template>
        </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="scope">
            {{ scope.row.remark }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <div class="base-table-operation">
              <el-link size="mini" type="primary" @click="handleEdit(scope.row)"
                >编辑</el-link
              >
              <el-link
                size="mini"
                type="danger"
                @click="handleDelete(scope.row)"
                >删除</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>

      <BasePagination
        :total="queryForm.total"
        :page-index="queryForm.pageIndex"
        :page-size="queryForm.pageSize"
        @sizeChange="sizeChange"
        @currentChange="currentChange"
      />
    </div>
    <EntrustTaskDistribution
      ref="EntrustTaskDistribution"
      :dialog-form-visible.sync="dialogFormVisible"
    />
  </div>
</template>

<script>
import {
  deleteRecord,
  GetEntrustTaskSampleDetection,
} from "../../../api/EntrustTaskManage/EntrustTask.js";
import EntrustTaskDistribution from "./EntrustTaskDistribution.vue";
export default {
  name: "EntrustTaskReview",
  components: { EntrustTaskDistribution },
  data() {
    return {
      loading: true,
      list: [],
      queryForm: {
        EntrustOrderNum: "",
        pageIndex: 1,
        pageSize: 10,
        total: 0,
      },
      dialogFormVisible: false,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    currentChange(val) {
      this.queryForm.pageIndex = val;
      this.getList();
    },
    sizeChange(val) {
      this.queryForm.pageIndex = 1;
      this.queryForm.pageSize = val;
      this.getList();
    },
    getList() {
      this.loading = true;
      GetEntrustTaskSampleDetection(this.queryForm)
        .then((res) => {
          this.list = res.data.dataList ? res.data.dataList : [];
          this.queryForm.total = res.data.total;
          this.loading = false;
        })
        .catch(() => {
          this.loading = false;
        });
    },
    entrustTaskDistributionFun() {
      this.dialogFormVisible = true;
    },
    handleDelete(rowData) {
      this.Helper.deleteConfirm(() => {
        this.loading = true;
        deleteRecord({ id: rowData.id })
          .then((res) => {
            this.getList();
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      });
    },

    onQuery() {
      this.getList();
    },
  },
};
</script>
